<template>
	<view class="blindPerson">
		<view class="" style="position: fixed;top: 0;left: 0;width: 750rpx;z-index: 99999;" v-if="ceShow">
			<u-notice-bar mode="horizontal" :list="noticeList"></u-notice-bar>
		</view>
		<u-modal v-model="show" :show-title="false" width="690" :show-confirm-button="false" z-index="20">
			<view class="slot-content">
				<view class="dialogMain">
					<view class="dialogMain_top">
						<image src="../../static/img/close.png" mode="" @click="closeDialog"></image>
					</view>
					<view class="" style="padding: 0 18rpx;border-bottom: 1rpx solid #e2e2e2;">
						<span>{{nowText}}</span>
						<u-input v-model="value" type="textarea" :border="false" :height="300" />
					</view>
					<view class="" v-if="can_upload == '1'">
						<u-upload :header="header" :action="action" :file-list="fileList" @on-success="success"
							@on-remove="remove" :max-count="9" width="181" height="181" upload-text=""></u-upload>
					</view>
					<view class="dialogMain_bottom">
						<view class="" @click="submit">
							发布
						</view>
					</view>
				</view>
			</view>
		</u-modal>


		<u-navbar back-text="返回" :title="title" title-color="#045B9B"></u-navbar>
		<view class="blindPerson_top">
			<view class="blindPerson_top_top">
				<view class="blindPerson_top_top_left">
					<image :src="info.image" mode=""></image>
				</view>
				<view class="blindPerson_top_top_right">
					<view class="blindPerson_top_top_right_Item">
						<u-icon name="account" color="#045B9B" size="28"></u-icon>
						<span>{{info.name}}</span>
					</view>
					<view class="blindPerson_top_top_right_Item">
						<u-icon name="woman" color="#045B9B" size="28" v-if="info.sex == 2"></u-icon>
						<u-icon name="man" color="#045B9B" size="28" v-else></u-icon>
						<span>{{info.sex_text}}</span>
					</view>
					<view class="blindPerson_top_top_right_Item">
						<u-icon name="man-add" color="#045B9B" size="28"></u-icon>
						<span>{{info.age}}</span>
					</view>
					<view class="blindPerson_top_top_right_Item">
						<u-icon name="grid" color="#045B9B" size="28"></u-icon>
						<span>{{info.hangye}}</span>
					</view>
					<view class="blindPerson_top_top_right_Item">
						<u-icon name="list-dot" color="#045B9B" size="28"></u-icon>
						<span>{{info.xueli}}</span>
					</view>
				</view>
			</view>
			<view class="">
				<image src="../../static/img/menu.png" mode="" style="width: 24rpx;height: 24rpx;margin-top: 20rpx;">
				</image>
			</view>
			<view class="blindPerson_top_bottom">
				<!-- <img src="../../static/img/menu.png" alt="" /> -->
				
				<rich-text class="blindPerson_top_bottomhtml" :nodes="info.demand" @itemclick.stop="goHtmlImage">

				</rich-text>
			</view>
		</view>
		<view class="bindDetail_bottom">
			<view class="bindDetail_bottom_item" v-for="(item,index) in list" :key="index">
				<view class="bindDetail_bottom_item_top">
					<view class="bindDetail_bottom_item_top_left">
						<image :src="item.user.avatar" mode=""></image>
						<span>{{item.user.nickname}}</span>
						<span style="margin-left: 20rpx;color: #999;">{{timestamp(item.createtime)}}</span>
					</view>
					<view class="bindDetail_bottom_item_top_right" @click="reply(item)">
						回复
					</view>
				</view>
				<view class="bindDetail_bottom_item_bottom">
					{{item.content}}
				</view>
				<view class="bindDetail_bottom_item_imgBox" v-if="item.images && item.images.length>0">
					<view class="" v-for="(imgItem,imgIndex) in item.images" :key="imgIndex"
						style="margin-right: 10rpx;margin-bottom: 10rpx;">
						<u-image width="150rpx" height="150rpx" :src="imgItem"
							@click="handleImage(item.images,imgIndex)"></u-image>
					</view>
				</view>
			</view>
			<view class="" style="padding: 20rpx 0;">
				<u-loadmore :status="status" />
			</view>
		</view>
		<view class="blindPerson_footer">
			<image src="../../static/img/btn1.png" mode="" @click="openDialog"></image>
			<image src="../../static/img/btn2.png" mode="" @click="goSl"></image>
		</view>
	</view>
</template>

<script>
	import {
		mapGetters
	} from 'vuex';
	import {
		baseUrl
	} from '@/config/config.js'
	import {
		getXqPsDetail,
		getWsDetailLy,
		getConfig,
		getUserChatId
	} from '@/api/index.js'
	export default {
		data() {
			return {
				action: '',
				fileList: [],
				show: false,
				nowText: '',
				value: '',
				status: 'loadmore',
				title: '',
				id: '',
				info: {},
				page: 1,
				limit: 10,
				list: [],
				baseUrl: '',
				header: {
					token: uni.getStorageSync('userInfo') ? uni.getStorageSync('userInfo').token : ''
				},
				replyUid: '',
				can_upload: '1',
				ceShow: false,
				noticeList: []
			}
		},
		methods: {
			goHtmlImage(e) {
				// console.log(e);
				let imgPath = e.detail.node.attrs.src;
				this.handlePreViewImage(imgPath);
			},
			handlePreViewImage(imgPath) {
				let arr = [];
				arr.push(imgPath);
				uni.previewImage({
					urls: arr,
					longPressActions: {
						itemList: ['保存图片到相册'],
						success: function(data) {
							console.log(data.tapIndex);
							if (data.tapIndex == 0) {
								uni.saveImageToPhotosAlbum({
									filePath: imgPath,
									success: function() {
										uni.showToast({
											title: '保存成功',
											duration: 2000
										});
									}
								});
							}
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			handleImage(arr, index) {
				uni.previewImage({
					current: index,
					urls: arr,
				});
			},
			async goSl() {
				let data = {
					user_id:this.info.hongniang_id
				}
				const res = await getUserChatId(data)
				if(res.data){
					uni.navigateTo({
						url:`/pages/views/privateChat/privateChat?chat_id=${res.data}&name=${this.info.hongniang.nickname}`
					})
				}
				// console.log(res);
				// let that = this
				// that.ws.pageFun(function() {
				// 	let message = {
				// 		c: 'Message',
				// 		a: 'openSession',
				// 		data: {
				// 			'id': that.info.hongniang.fastim_id,
				// 			'type': 'user'
				// 		}
				// 	}
				// 	that.ws.send(message);
				// }, that)
			},
			openDialog() {
				this.nowText = ''
				this.replyUid = ''
				this.show = true
			},
			reply(item) {
				// console.log(item);
				this.nowText = `@${item.user.nickname}`
				this.replyUid = item.user_id
				this.show = true
			},
			success(data, index, lists, name) {
				// console.log(data, index, lists, name);
				this.fileList = lists
			},
			remove(index, lists, name) {
				this.fileList = lists
			},
			closeDialog() {
				this.show = false
				this.value = ''
				this.nowText = ''
				this.fileList = []
			},
			async config() {
				const res = await getConfig()
				this.can_upload = res.data.can_upload
			},
			timestamp(timestamp) {
				var date = new Date(timestamp * 1000); // 转换为毫秒
				var year = date.getFullYear();
				var month = ('0' + (date.getMonth() + 1)).slice(-2);
				var day = ('0' + date.getDate()).slice(-2);
				var hours = ('0' + date.getHours()).slice(-2);
				var minutes = ('0' + date.getMinutes()).slice(-2);
				var seconds = ('0' + date.getSeconds()).slice(-2);

				return year + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
			},
			async submit() {
				// console.log(this.fileList);
				if (this.value == '') {
					return uni.showToast({
						icon: 'none',
						title: '请输入内容'
					})
				}
				let data = {
					id: this.id,
					content: this.nowText + ' ' + this.value,
					uid: this.replyUid,
					images: this.fileList.map(e => {
						return e.response.data.url
					}).join(',')
				}
				const res = await getWsDetailLy(data)
				uni.showToast({
					icon: 'none',
					title: res.msg
				})
				this.closeDialog()
				this.page = 1
				this.list = []
				this.getInfo()
			},
			async getInfo() {
				this.status == 'loading'
				let data = {
					id: this.id,
					page: this.page,
					limit: this.limit
				}
				const res = await getXqPsDetail(data)
				// console.log(3213,res);
				res.data.info.demand = res.data.info.demand.replace(/<img/gi, "<img class='richImg'")
				res.data.info.demand = res.data.info.demand.replace(/height\s*:\s*[^;]+;?\s*/g, '');
				this.info = res.data.info
				this.list = [...this.list, ...res.data.list.data]
				// console.log(this.list);
				if (res.data.list.data.length < this.limit) {
					this.status = 'nomore'
				} else {
					this.status = 'loadmore'
				}
			}
		},
		onLoad(e) {
			this.ws.pageFun(this.pageDataLoad, this);
			this.baseUrl = baseUrl
			this.action = baseUrl + '/api/common/upload'
			this.title = e.name
			this.id = e.id
			this.getInfo()
			this.config()
		},
		onReachBottom() {
			if (this.status == 'nomore') return
			this.page++
			this.getInfo()
		},
		watch: {
			socketMessage(newVal, oldVal) {
				if (newVal) {
					this.ceShow = true
					this.noticeList = [newVal.slice(0,-1)]
					setTimeout(() => {
						this.ceShow = false
					}, 10000)
				}
			}
		},
		computed: {
			...mapGetters(['getSocketMessage']),
			socketMessage() {
				return this.getSocketMessage;
			}
		},
	}
</script>

<style scoped lang="scss">
	.blindPerson {
		min-height: 100vh;
		background-color: #fff;
		padding: 30rpx;
		padding-bottom: 150rpx;
		.richImg {
			width: 100% !important;
			height: auto !important;
		}

		.dialogMain {
			padding: 30rpx;

			.dialogMain_top {
				display: flex;
				justify-content: flex-end;

				image {
					width: 23rpx;
					height: 23rpx;
				}
			}

			.dialogMain_bottom {
				display: flex;
				justify-content: flex-end;
				color: #045B9B;
				padding-right: 18rpx;
				padding-bottom: 16rpx;
				margin-top: 16rpx;
			}
		}

		.bindDetail_bottom {
			padding: 0 30rpx;

			.bindDetail_bottom_item {
				padding: 33rpx 0;
				border-bottom: 1rpx solid #E2E2E2;

				.bindDetail_bottom_item_imgBox {
					padding-left: 74rpx;
					width: 554rpx;
					display: flex;
					align-items: center;
					flex-wrap: wrap;
					margin-top: 20rpx;

					image {
						width: 150rpx;
						height: 150rpx;
					}
				}

				.bindDetail_bottom_item_top {
					display: flex;
					justify-content: space-between;
					align-items: center;

					.bindDetail_bottom_item_top_left {
						display: flex;
						justify-content: space-between;
						align-items: center;

						image {
							width: 48rpx;
							height: 48rpx;
							margin-right: 25rpx;
						}

						span {
							color: #045B9B;
							font-size: 26rpx;
							max-width: 480rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}

					.bindDetail_bottom_item_top_right {
						font-size: 26rpx;
						color: #999;
					}
				}

				.bindDetail_bottom_item_bottom {
					margin-top: 10rpx;
					font-size: 26rpx;
					padding-left: 74rpx;
				}
			}
		}

		.blindPerson_footer {
			width: 100%;
			height: 120rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 27rpx;
			padding-bottom: 30rpx;
			position: fixed;
			left: 0;
			bottom: 0;
			background-color: #fff;
			z-index: 99;

			image {
				width: 300rpx;
				height: 60rpx;
			}
		}

		.blindPerson_top {
			padding: 0 30rpx;

			.blindPerson_top_top {
				display: flex;
				justify-content: space-between;

				.blindPerson_top_top_left {
					width: 228rpx;
					height: 228rpx;

					image {
						width: 100%;
						height: 100%;
						border-radius: 20rpx;
					}
				}

				.blindPerson_top_top_right {
					width: 394rpx;
					height: 228rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-between;

					.blindPerson_top_top_right_Item {
						display: flex;
						align-items: center;
						font-size: 22rpx;

						span {
							margin-left: 15rpx;
							max-width: 340rpx;
							overflow: hidden;
							text-overflow: ellipsis;
							white-space: nowrap;
						}
					}
				}
			}

			.blindPerson_top_bottom {
				width: 100%;
				// margin-top: 22rpx;
				padding-bottom: 40rpx;
				border-bottom: 1rpx solid #e2e2e2;
				// background-color: red;

				image {
					width: 24rpx;
					height: 24rpx;
					float: left;
					margin-top: 8rpx;
					margin-right: 10rpx;
				}

				.blindPerson_top_bottomhtml {
					width: 630rpx;

					::v-deep img {
						max-width: 100%;
					}
				}
			}
		}
	}
</style>